//
//  zlgd.m
//  PASystem
//
//  Created by michael on 16/8/24.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "zlgd.h"

@implementation zlgd
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
    UIColor *myColor = [UIColor colorWithWhite:0.8 alpha:0.3];
self.backgroundColor = myColor;


          }
    return self;
}
- (void)setId:(NSString *)id{


//NSLog(@"11%@",id);
_id = id;
 [self initview];
[self request];
 
}
- (void)initview{
_tableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableview.frame = CGRectMake(10, 10, KScreenWidth-20, KScreenHeight-80-46-64-20);

_tableview.dataSource = self;
_tableview.delegate = self;
self.tableview.bounces = NO;
[self addSubview:_tableview];





}
- (void)request{
NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
 NSString *json =[NSString stringWithFormat: @"{'action':zlgdMch,'service':DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,_id];
     NSArray * array = @[@{@"arg0":json}];
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {

    NSArray *updic = JSON[@"reason"];

       _dataArray = [NSMutableArray array];
       
for (NSDictionary *dic in updic) {
    _dic = dic[@"attrs"];
    [_dataArray addObject:_dic];
}
[_tableview reloadData];
//       NSLog(@"%@",_dataArray);

    } failure:^(NSError *error) {
        
    }];



}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  _dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

return 60;
}

#pragma mark UITableView dataScource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
 static NSString *CellIdentifier = @"Cell111111";  

    zlgdTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell==nil) {  
        cell=[[zlgdTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    NSDictionary *dic = _dataArray [indexPath.row];
    cell.dic = dic;
//cell.action = _action;
    return cell;
}


@end
